﻿@model IEnumerable<WebSoftSeo.Models.Consult>
@using WebSoftSeo.Models
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
    WebSoftSeoEntities db = new WebSoftSeoEntities();
    var list = db.Consults.ToList();
}
<div class="mar10 borall">
    <table class="formtable">
        <tbody>
            <tr>
                <th>Tên</th>
                <th>Email</th>
                <th>Tiêu Đề và Nội Dung</th>
                <th>Phone</th>
                <th>Ngày</th>
                <th>Status</th>
                <th>IP</th>
                <th>Trả Lời</th>
                <th>Action</th>
            </tr>
            @foreach (var item in Model)
            {
                <tr>
                    <td width="14%"><b>@Html.DisplayFor(modelItem => item.Name)</b></td>
                    <td width="14%">
                        <p class="commentColor">@Html.DisplayFor(modelItem => item.Email)</p>
                    </td>
                    <td width="28%">
                        <p style="margin-left: 160px; font-size: 15px; color: red">@Html.DisplayFor(modelItem => item.Title)</p>
                        <p class="commentColor">@Html.DisplayFor(modelItem => item.Contents)</p>

                        @{
                var listlevel2 = list.Where(m => m.ParentID == item.ID).OrderByDescending(c => c.ID).ToList();
                        }
                        @foreach (var lv2 in listlevel2)
                        {
                            <div class="replyname">
                                <p>Trả Lời: @lv2.Contents</p>
                                <a title="Xóa trả lời" style="color:red;float:right;" href="/@WebSoftSeo.Models.GlobalVariables.PathFolderName/Consult/Delete?id=@lv2.ID" >| Xóa trả lời</a>

                                <div id="row3-@lv2.ID" style="float: right; color:blue;">

                                    @if (lv2.Status == false)
                                    {
                                        <text>Waiting</text>
                                        <input type="checkbox" name="status" class="addstatus" data-id="@lv2.ID" />
                                    }
                                    else
                                    {
                                        <text>Approved</text>
                                    }

                                </div>
                            </div>
                                   
                        }
                    </td>
                    <td width="9%">
                        @Html.DisplayFor(modelItem => item.Phone)
                    </td>
                    <td width="9%">
                        @Html.DisplayFor(modelItem => item.Date)
                    </td>
                    <td width="7%" id="row-@item.ID">
                        @if (item.Status == false)
                        {
                            <text>Waiting</text>
                            <input type="checkbox" name="status" class="addstatus" data-id="@item.ID" />
                        }
                        else
                        {
                            <text>Approved</text>
                        }
                    </td>
                    <td width="9%">
                        @Html.DisplayFor(modelItem => item.IPuser)
                    </td>
                    <td width="5%" id="row2-@item.ID">
                        @if (item.Status == true)
                        {
                            <a title="Trả lời" style="color: blue" href="/@WebSoftSeo.Models.GlobalVariables.PathFolderName/Consult/Reply?id=@item.ID">Trả Lời</a> 
                        }
                    </td>
                    <td width="5%">
                        <a class="button red" title="Xóa Tất Cả" href="/@WebSoftSeo.Models.GlobalVariables.PathFolderName/Consult/Delete?id=@item.ID" >
                            <div class="icon">
                                <p class="ic-delete"></p>
                            </div>
                        </a>
                    </td>


                </tr>
            }
        </tbody>

    </table>
    <script>$("tr:even").css("background-color", "#f2f2f2");</script>
</div>
<div class="clear"></div>
<div class="mar10">
    @using (Ajax.BeginForm(new AjaxOptions
        {
            UpdateTargetId = "result",
            InsertionMode = InsertionMode.Replace
        }))
    {
        var pi = WebSoftSeo.Utility.PagerInfo.Get("Consult", 10);
       
        <input class="buttonpage" type="submit" value="<< " name="PageNo:0" />
        <input class="buttonpage"  title="Previous" type="submit" value="<" name="PageNo:@(pi.PageNo - 1)" />
        for (var i = pi.PageNo - 3; i < pi.PageNo; i++)
        {
            if (i >= 0)
            {
        <input class="buttonpage"  title="Next" type="submit" value="@i" name="PageNo:@i" />
            }
        }
        <input class="buttonpage pagenaviselect" title="Next" type="submit" value="@pi.PageNo" name="PageNo:@(pi.PageNo)" />
        
        for (var i = pi.PageNo + 1; i < pi.PageNo + 3; i++)
        {
            if (i < pi.PageCount)
            {
        <input class="buttonpage"  title="Next" type="submit" value="@i" name="PageNo:@i" />
            }
        }
        <input class="buttonpage"  title="Next" type="submit" value=">" name="PageNo:@(pi.PageNo + 1)" />
        <input class="buttonpage"  type="submit" value=" >>" name="PageNo:@(pi.LastPageNo)" /> 
    }
</div>
<script type="text/javascript">
    $('.addstatus').click(function () {
        countToUpdate = $(this).val();
        var idc = $(this).attr("data-id");
        if ($(this).attr('checked')) {
            $.post("/Consult/Edit", { "id": idc },
                        function (data) {
                            $('#row-' + idc).text(data);
                        });
            $.post("/Consult/EditReply", { "id": idc },
                        function (data) {
                            $('#row2-' + idc).html('<a title="Trả lời" style="color: blue" href="/@WebSoftSeo.Models.GlobalVariables.PathFolderName/Consult/Reply?id=' + data + '">Trả lời</a>');
                        });
                        $.post("/Consult/Edit", { "id": idc },
                                    function (data) {
                                        $('#row3-' + idc).text(data);
                                    });

                    }
    });
</script>